/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-08-24     yangjie      the first version
 */

/*
* 程序清单：相同优先级线程按照时间片轮转调度
*
* 这个例子中将创建两个线程，每一个线程都在打印信息
*
*/

#include <aos/aos.h>
#include "aos/cli.h"
#include <debug/dbg.h>

#define THREAD_STACK_SIZE   4096
#define THREAD_PRIORITY     20
#define THREAD_TIMESLICE    10

/* 线程入口 */
static void thread_entry(void *parameter)
{
    uint32_t value;
    uint32_t count = 0;

    value = (uint32_t)(uintptr_t)parameter;
    while (1)
    {
        if (0 == (count % 5))
        {
            aos_debug_printf("thread %d is running ,thread %d count = %d\n", value, value, count);

            if (count > 200)
                return;
        }
        count++;
    }
}

int yoc_timeslice_sample(int argc, char **argv)
{
    aos_task_t tid = NULL;

    /* 创建线程1 */
    aos_task_create(&tid,
                    "thread1",
                    thread_entry, (void*)1,
                    NULL,
                    THREAD_STACK_SIZE,
                    THREAD_PRIORITY, AOS_TASK_AUTORUN);

    /* 创建线程2 */
    aos_task_create(&tid,
                    "thread2",
                    thread_entry, (void*)2,
                    NULL,
                    THREAD_STACK_SIZE,
                    THREAD_PRIORITY, AOS_TASK_AUTORUN);
    return 0;
}

ALIOS_CLI_CMD_REGISTER(yoc_timeslice_sample, yoc_timeslice_sample, yoc timeslice sample);

